from django.db import models
from django.core.validators import MinLengthValidator

class User(models.Model):
    user_id = models.AutoField(primary_key=True)
    username = models.CharField(
        max_length=50,
        unique=True,
        validators=[MinLengthValidator(4)],  # 可选：添加用户名最小长度验证
        error_messages={
            'unique': '该用户名已被占用',
        }
    )
    email = models.EmailField(
        max_length=255,
        unique=True,
        error_messages={
            'unique': '该邮箱已被注册',
        }
    )
    password = models.CharField(max_length=100)
    information = models.CharField(max_length=200, blank=True, null=True)

    class Meta:
        db_table = 'users'  # 指定数据库表名
        verbose_name = '用户'
        verbose_name_plural = '用户'

    def __str__(self):
        return self.username